package com.huatai.exchange.integration.support.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.faneui.common.utils.MapUtils;
import com.faneui.integration.http.HttpClientUtils;
import com.huatai.exchange.integration.support.AbstractSupportService;
import com.huatai.exchange.integration.support.service.ScheduleBatchService;
import com.huatai.support.facade.bean.QueryScheduleBatchVoListResp;
import com.huatai.support.facade.bean.ScheduleBatchVo;
import com.huatai.support.facade.bean.schedule.RegisterScheduleBatchReq;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleBatchServiceImpl extends AbstractSupportService implements ScheduleBatchService {

    @Override
    public void registerScheduleBatch(RegisterScheduleBatchReq req) throws BusinessException {
        String url = baseUrl + "schedule/register";
        HttpClientUtils.post(url,req);
    }

    @Override
    public List<ScheduleBatchVo> queryScheduleBatchVoList(String occurDate, String businSystemCode, String businId) throws BusinessException {
        String url = baseUrl + "schedule/batch/list" ;
        ScheduleBatchVo param = new ScheduleBatchVo();
        param.setOccurDate(occurDate);
        param.setBusinId(businId);
        param.setBusinSystemCode(businSystemCode);
        List<ScheduleBatchVo> vos = HttpClientUtils.get(url, MapUtils.parseMap(param), QueryScheduleBatchVoListResp.class).getScheduleBatchVos();
        if(ListUtils.isEmpty(vos))
            return null;
        return vos;
    }

    @Override
    public List<ScheduleBatchVo> queryScheduleBatchVoList(ScheduleBatchVo scheduleBatchVo) throws BusinessException {
        String url = baseUrl + "schedule/batch/list" ;
        return HttpClientUtils.get(url,scheduleBatchVo,QueryScheduleBatchVoListResp.class).getScheduleBatchVos();
    }

    @Override
    public ScheduleBatchVo queryScheduleBatchVo(String occurDate, String businId) throws BusinessException {
        List<ScheduleBatchVo> vos =  queryScheduleBatchVoList(occurDate,businSystemCode,businId) ;
        if(ListUtils.isEmpty(vos))
            return null;
        return vos.get(0);
    }
}
